package com.ckd.flyingtrip.adapter;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.activity.BaseActivity;
import com.ckd.flyingtrip.javabean.DingdanBean;
import com.ckd.flyingtrip.utils.Tools;

import java.util.List;

public class VehicleAdapter extends BaseAdapter {

    private BaseActivity context;
    private Onc_battery close_battery;
    private List<DingdanBean> list;
    private int checked = 0;//初始选择为-1，position没有-1嘛，那就是谁都不选咯
    public interface Onc_battery{
        public void click(View v,int posin);
    }
    public VehicleAdapter(BaseActivity context, Onc_battery close_battery,List<DingdanBean> list){
        this.context = context;
        this.list = list;
        this.close_battery = close_battery;
    }

    public void setChecked(int checked) {//设定一个选中的标志位，在activity中传入值。
        this.checked = checked;
    }
    @Override
    public int getCount() {
        if (Tools.isEmpeyNull(list)) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        View view = null;
        if (convertView == null) {
            view = View.inflate(context, R.layout.item_title_txt, null);
            holder = new ViewHolder();
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ViewHolder) convertView.getTag();
        }
        holder.txt_title = view.findViewById(R.id.txt_title);
        DingdanBean dingdanBean = list.get(position);
        holder.txt_title.setText(dingdanBean.getBicycleName());
        if (checked == position) {
            holder.txt_title.setTextColor(Color.parseColor("#FD5B0E"));
        }else {
            holder.txt_title.setTextColor(Color.parseColor("#454C52"));
        }
        return view;
    }

    public static final class ViewHolder {
        private TextView txt_title;
    }
}